/*
Copyright (C) 2021-2025 Casa Xu (also Zhiyan Xu) from HIT

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*
 * LOS_State.h
 *
 *  Created on: 2022年10月17日
 *      Author: 64435
 */

#ifndef OS_LAYER_INC_LOS_STATE_H_
#define OS_LAYER_INC_LOS_STATE_H_
#include "LOS_SYS.h"
#include "LOS_FATFS.h"
#include "LOS_FlightProcedure.h"

#define NOW_FLASH0  //这套程序是FLASH0程序
#define SOFTVERSION 7

#define TMTC2SD_UPFSIZE 240 //一次从测控/数传读取到SD卡的上注文件大小

//延时遥测文件最大值
#define TM_DTM_MAXIMUM 62899200

//上电以后不操作的时间
#define LOS_RST_WAITDUR 900

#define TKSAX1_CODE 0
#define TKSAX2_CODE 1
#define TKUHF1_CODE 2
#define TKUHF2_CODE 3
#define TKVHF1_CODE 4
#define TKVHF2_CODE 5
#define TKLEN1_CODE 6
#define TKLEN2_CODE 7

typedef struct LOS_AOCSMODE_t
{
    uint16_t mode;
    uint16_t TCmode; //遥控上注的模式
    uint32_t starttime;
    uint32_t durtime;
    uint8_t AM_TCFLAG;
}LOS_AOCSMODE_t;

LOS_AOCSMODE_t MODE_AOCS;

extern RSEnDeCode_t FT_Struct;

extern uint8_t MAX14830_SELFSTA1[2];
extern uint8_t MAX14830_SELFSTA2[2];

extern uint8_t UP_BUF[TMTC2SD_UPFSIZE+4];

extern uint8_t LOS_HL_RBTP;
extern uint8_t LOS_HL_RECOVP;

extern LOS_AOCSMODE_t MODE_AOCS;

extern uint8_t LOS_SAT_SafeModeCNT;
extern uint8_t LOS_SAT_SoftSafeMode;

extern uint8_t LOS_CPU;
extern uint8_t RTOS_FLAG_Update1;
extern uint8_t RTOS_FLAG_FATFS0;
extern uint8_t LOS_FLASH_ID;
extern uint8_t LOS_UPLOAD_FileNum;
extern uint32_t LOS_UPLOAD_FileSize;
extern uint8_t LOS_UPLOAD_CNT;
extern uint8_t LOS_UPLOAD_TC2OBC;
extern uint8_t LOS_UPLOAD_DT2OBC;
extern uint32_t LOS_UPLOAD_ReadFinishTime;
extern uint32_t LOS_UPLOAD_DownFinishTime;
extern uint8_t STATE_UPLOAD_OPENFILE;
extern uint8_t STATE_UPLOAD_SD2FLASHDONE;
extern uint8_t PERMIT_UPLOAD_SD2FLASH;
extern uint32_t LOS_UPLOAD_BlockSize;
extern uint32_t LOS_UPLOAD_OffSet;
extern uint32_t LOS_UPLOAD_BlockCnt;
extern uint32_t LOS_UPLOAD_FileReceived;
extern uint8_t LOS_UPLOAD_LASTPACK;
extern uint32_t Jump_Addr_FLASH;   
extern uint8_t PERMIT_UPLOAD_JUMP;
extern uint16_t LOS_ModeAcsIn;
extern float LOS_Targetq[4];
extern float LOS_Targetpos[3];
extern uint16_t CTRL_TM_CNT;
extern uint16_t EPS_TM_CNT;
extern uint8_t MAX_RESET_FLAG;
extern uint16_t MAX_RESET_CNT;
extern uint8_t DBG_PORT;
extern uint32_t AOCS_Enter_Times;
extern uint16_t LOS_TC_READ;
extern uint16_t LOS_TC_EX;
extern uint32_t LOS_TC_LASTCMD;
extern uint32_t LOS_TC_FirstDelayCMD;
extern uint32_t LOS_TC_FirstDelayTime;
extern uint32_t LOS_TC_LASTCMDTIME;
extern uint16_t LOS_TC_NOWTask;
extern uint32_t LOS_TC_NOWTaskTime;
extern uint32_t LOS_TC_TaskNum;
extern uint16_t LOS_PCDU_CMDCNT;
extern uint16_t LOS_PCDU_EXCMDCNT;
extern uint16_t LOS_PCDU_LASTCMD;
extern uint8_t LOS_FW_PERMIT;
extern uint8_t LOS_MT_PERMIT;

extern uint32_t LOS_UPFILE_SIZE;

extern uint8_t LOS_TM_UnitSta[3];
extern uint8_t LOS_TM_SATSta;
extern uint8_t LOS_TM_RBTnID;
extern uint32_t LOS_TM_RBTTime;

extern uint8_t LOS_TESTM_FLAG;
extern uint32_t LOS_TESTM_DUR;
extern uint32_t LOS_TESTM_ENT;
extern uint32_t LOS_TESTM_LEFT;

extern uint8_t LOS_TM_ID[6];
extern uint8_t LOS_TM_Type[6];
extern uint16_t LOS_TM_PackNum[6];


extern uint16_t LOS_TM_FreCtrl;
extern uint16_t LOS_TM_InvTime;
extern uint16_t LOS_TM_AdjustInvDur;
extern uint16_t LOS_TM_CMOSTRAN;
extern uint8_t LOS_DT_TMPERMIT;

extern uint8_t LOS_HFT_STA;

extern uint32_t CRC32_SD_SAVE;
extern uint32_t CRC32_SD_OBCCAL;
extern uint32_t CRC32_SD_OFFSET;
extern uint32_t CRC32_TC_TRAN;
extern uint32_t LOS_SD2FLASH_SIZE;

extern hetSIGNAL_t signal_test;
extern uint32_t test_bit;

extern uint8_t LOS_MagTrqPermit;

extern uint8_t CMOS_PICCNT;
extern uint32_t CMOS_TOTALSIZE;
extern uint32_t CMOS_FILESIZE;
extern uint32_t CMOS_NOWSIZE;
extern uint8_t CMOS_LASTFRAME;
extern uint32_t CMOS_PICSIZE;
extern uint8_t LOS_CMOS_CAM2OBC;
extern uint8_t LOS_CMOS_PICNUM;
extern uint16_t LOS_CMOS_Invbuf;
extern uint8_t LOS_CMOS_OBC2TM;
extern uint8_t LOS_CMOS_NUMBUF;
extern uint32_t LOS_CMOS_OBC2TCLEFT;

extern float LOS_ORB_OE[6];
extern float LOS_ORB_RV[6];
extern uint8_t LOS_ORB_UPFLAG;

extern uint8_t MAX14830_CHECKTEST[12];

extern uint8_t PCDU_CRC8CHECK[10];

extern uint8_t TMTC_PERMITARG;

extern uint8_t LOS_TK_SEL[8];
extern uint32_t LOS_UP_BASEADDR;

#endif /* OS_LAYER_INC_LOS_STATE_H_ */
